#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <stdlib.h>

struct libo
{
	int va;
	libo* next;
};

typedef struct libo libo;


libo* CreNode(int x)
{
	libo* pl;
	pl = (libo*)malloc(sizeof(libo));
	if (pl == NULL)
	{
		perror("malloc");
		exit(1);
	}
	pl->va = x;
	pl->next = NULL;
	return pl;
}
 
libo* CreXun(int n)
{
	libo* phead = CreNode(1);
	libo* tmp1 = phead;
	libo* tmp2;
	for (int i = 0; i < n - 1; i++)
	{
		tmp2 = CreNode(i);
		tmp1->next = tmp2;
		tmp1 = tmp2;
	}
	tmp1->next = phead;
	return phead;
}

libo* SerC(int n,int m)
{
	libo* head = CreXun(n);
	libo* tmp1 = head;
	libo* tmp2 = head;
	while (n - 1)
	{
		int a = 1;
		while (a - m)
		{
			a++;
			tmp2 = tmp1;
			tmp1 = tmp1->next;
		}
		if (n - 2)
		{
			tmp2->next = tmp1->next;
		}
		else
		{
			tmp2->next = NULL;
		}
		n--;
	}
	return tmp2;
}

int main()
{
	printf("%d",SerC(5, 2)->va);
	return 0;
}